from numpy.distutils.system_info import accelerate_info

from src.baseapp.core.device.device.baseDevice import BaseDevice
from src.baseapp.core.device.device.s5lDeivceController import S5lDeviceController


class DeviceFactory:
    BaseDevice = BaseDevice

    active_device = set()

    type_device_mapping = {
        "s5l": S5lDeviceController
    }

    @classmethod
    def create_device(cls, name, imei, ip, port, protocol_type):
        device_cls = cls.type_device_mapping.get(protocol_type)
        if device_cls:
            device = device_cls(name, imei, ip, port, protocol_type)
            cls.active_device.add(device)
            return device
        return None

    @classmethod
    def get_device(cls, imei):
        for device in cls.active_device:
            if device.imei == imei:
                return device
        return None

    @classmethod
    def remove_device(cls, imei):
        for device in cls.active_device:
            if device.imei == imei:
                device.deactive()
                cls.active_device.remove(device)
                return True
        return False